package com.yunxin.download.server.infra.repository;

import com.yunxin.download.server.infra.repository.mapper.DownloadRecordMapper;
import com.yunxin.download.server.model.entity.DownloadRecord;
import com.yunxin.download.server.model.query.result.DownloadRecordPageCondition;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * @author zero°
 * @since 2023-06-13
 */
@Repository
public interface DownloadRecordDao extends DownloadRecordMapper {

    /**
     * 分页查询下载记录总条数
     *
     * @param condition condition
     * @return int
     */
    long countDownloadRecordPageQuery(DownloadRecordPageCondition condition);

    /**
     * 分页查询下载记录列表
     *
     * @param condition condition
     * @return List<DownloadRecord>
     */
    List<DownloadRecord> downloadRecordPageQuery(DownloadRecordPageCondition condition);

    /**
     * 获取可过期下载记录列表
     *
     * @param startTime startTime
     * @return
     */
    List<DownloadRecord> expireList(@Param("startTime") Date startTime);

    /**
     * 获取未下载文件数量
     * @param downloaderName downloaderName
     *
     * @return int
     */
    int getUnDownloadCount(@Param("downloaderName") String downloaderName);

    /**
     * 批量更新下载记录下载状态
     *
     * @param ids                ids
     * @param downloadFileStatus downloadFileStatus
     * @return int
     */
    int batchUpdateDownloadFileStatus(@Param("ids") List<Long> ids,
                                      @Param("downloadFileStatus") Integer downloadFileStatus);
}
